package net.realsee.service.wcs.data.impl;

import cn.hutool.core.bean.BeanUtil;
import net.realsee.common.utils.StringUtils;
import net.realsee.framework.core.page.TableDataInfo;
import net.realsee.framework.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import net.realsee.domain.wcs.data.bo.WcsZoneRelationTypeBo;
import net.realsee.domain.wcs.data.vo.WcsZoneRelationTypeVo;
import net.realsee.domain.wcs.data.WcsZoneRelationType;
import net.realsee.mapper.wcs.data.WcsZoneRelationTypeMapper;
import net.realsee.service.wcs.data.IWcsZoneRelationTypeService;

import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 区域间关系类型Service业务层处理
 *
 * @author realsee
 * @date 2023-08-24
 */
@RequiredArgsConstructor
@Service
public class WcsZoneRelationTypeServiceImpl extends ServiceImpl<WcsZoneRelationTypeMapper, WcsZoneRelationType> implements IWcsZoneRelationTypeService {

    private final WcsZoneRelationTypeMapper baseMapper;

    /**
     * 查询区域间关系类型
     */
    @Override
    public WcsZoneRelationTypeVo selectVoById(Long id){
        return baseMapper.selectVoById(id);
    }

    /**
     * 查询区域间关系类型列表
     */
    @Override
    public TableDataInfo<WcsZoneRelationTypeVo> selectVoPage(WcsZoneRelationTypeBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<WcsZoneRelationType> lqw = buildVoQueryWrapper(bo);
        Page<WcsZoneRelationTypeVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询区域间关系类型列表
     */
    @Override
    public List<WcsZoneRelationTypeVo> selectVoList(WcsZoneRelationTypeBo bo) {
        LambdaQueryWrapper<WcsZoneRelationType> lqw = buildVoQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<WcsZoneRelationType> buildVoQueryWrapper(WcsZoneRelationTypeBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<WcsZoneRelationType> lqw = Wrappers.lambdaQuery();
        lqw.eq(StringUtils.isNotBlank(bo.getRelationType()), WcsZoneRelationType::getRelationType, bo.getRelationType());
        lqw.eq(StringUtils.isNotBlank(bo.getTypeDesc()), WcsZoneRelationType::getTypeDesc, bo.getTypeDesc());
        return lqw;
    }

    /**
     * 新增区域间关系类型
     */
    @Override
    public Boolean insertByBo(WcsZoneRelationTypeBo bo) {
        WcsZoneRelationType add = BeanUtil.toBean(bo, WcsZoneRelationType.class);
        return this.save(add);
    }

    /**
     * 修改区域间关系类型
     */
    @Override
    public Boolean updateByBo(WcsZoneRelationTypeBo bo) {
        WcsZoneRelationType update = BeanUtil.toBean(bo, WcsZoneRelationType.class);
        return this.updateById(update);
    }

    /**
     * 批量删除区域间关系类型
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids) {
        return this.removeBatchByIds(ids);
    }
}
